﻿using LearnEnglishWords.UI.ViewModels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Media.SpeechSynthesis;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556

namespace LearnEnglishWords.UI.Views
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class WordDemostrationView : Page
    {
        public WordDemostrationView()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            
        }

        private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var vm = DataContext as WordDemostrationViewModel;
            vm.ChangeLanguage();
        }

        private void OnNextClick(object sender, RoutedEventArgs e)
        {
            WithVM(x => x.GoToNextWord());
        }

        private void WithVM(Action<WordDemostrationViewModel> act)
        {
            var vm = DataContext as WordDemostrationViewModel;
            if (vm != null && act != null)
                act(vm);
        }

        private void OnKnownClick(object sender, RoutedEventArgs e)
        {
            WithVM(x => x.MarkAsKnowns());
        }

        private async void OnSoundClick(object sender, RoutedEventArgs e)
        {
            var vm = DataContext as WordDemostrationViewModel;
            await vm.PlayEnglishWord(Media);
        }

        
    }
}
